home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
c
/
optans10.zip
/
DEMOANSI.C
next >
Wrap
C/C++ Source or Header
|
1992-06-14
|
13KB
|
460 lines
#include "optansi.h"
#include "auser.h"
#include "skeys.h"
#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
/* Global variables */
// Counters and Timers
unsigned ocnt, nocnt;
clock_t begin, otime, notime;
pl(char *s) {
printf(s);
aupdatexy();
if(getch()==27)
exit(1);
return;
}
int test1() {
#define MEMBERS 10
// X positions
const char x[]={ 1, 2, 78, 78, 1, 1, 39, 39, 1, 1 };
// Y positions
const char y[]={ 1, 2, 2, 24, 24, 2, 12, 13, 14, 1 };
// Attributes
const char a[]={ 2, 7, 15, 31, 14, 13, 63,191, 79, 7 };
int i, j;
// Optimizations Count
acolor(7);
aclrscr();
ocnt=0;
otime=0;
for (j=0; j<100; j++) {
for (i=0; i<MEMBERS; i++) {
begin=clock();
ocnt+=agotoxy(x[i], y[i]); // Move cursor to new position
ocnt+=acolor(a[i]); // Set new color
printf("%X\b", i); // Put hex number
ocnt++; // Add 1 for output of hex character
otime+=clock()-begin;
if (!j) {
gotoxy(65, 1); // conio functions used to avoid interfering with ANSI
printf("X%d Y%d A%d %X", x[i], y[i], a[i], i);
aclreol();
if (getch()==27)
exit(1);
if (i==MEMBERS-1) {
gotoxy(63, 1);
atextattr(7);
printf("Now 100x repeated");
if (getch()==27)
exit(1);
}
gotoxy(x[i], y[i]); // Restore location
}
}
begin=clock();
ocnt+=acolor(7); // Set color for clear screen to black
ocnt+=aclrscr(); // Clear the screen
otime+=clock()-begin;
}
// Non-optimizations Count
atextattr(7);
aclrscr();
gotoxy(63, 1);
pl("Now Nonoptimized");
nocnt=0;
notime=0;
for (j=0; j<100; j++) {
for (i=0; i<MEMBERS; i++) {
begin=clock();
nocnt+=oldgotoxy(x[i], y[i]); // Move cursor to new position
nocnt+=oldcolor(a[i]); // Set new color
printf("%X\b", i); // Put hex number
nocnt++; // Add 1 for output of hex character
notime+=clock()-begin;
}
begin=clock();
nocnt+=oldcolor(7); // Set color for clear screen to black
nocnt+=oldclrscr(); // Clear the screen
notime+=clock()-begin;
}
return;
}
int test2() {
int i, j;
struct point {
char x, y, a;
} *ptr, *st;
if ((st = malloc(100*MEMBERS*sizeof(struct point))) == NULL)
{
printf("Not enough memory for Test 2\n");
return(0);
}
ptr=st;
// Optimizations Count
randomize();
acolor(7);
aclrscr();
ocnt=0;
otime=0;
for (j=0; j<100*MEMBERS; j++) {
ptr->x=random(80)+1;
ptr->y=random(24)+1;
ptr->a=random(256);
begin=clock();
ocnt+=agotoxy(ptr->x, ptr->y); // Move cursor to new position
ocnt+=acolor(ptr->a); // Set new color
ocnt+=printf("%X", j); // Put hex number
aupdatexy();
otime+=clock()-begin;
ptr++;
}
ptr=st;
// Non-optimizations Count
gotoxy(63, 1);
atextattr(7);
pl("Now Nonoptimized");
aclrscr();
nocnt=0;
notime=0;
for (j=0; j<100*MEMBERS; j++) {
begin=clock();
nocnt+=oldgotoxy(ptr->x, ptr->y); // Move cursor to new position
nocnt+=oldcolor(ptr->a); // Set new color
nocnt+=printf("%X", j); // Put hex number
notime+=clock()-begin;
ptr++;
}
free(st);
return(1);
}
test3() {
char s[25];
unsigned i;
/* LOCATION FUNCTIONS */
aclrscr();
pl("LOCATION FUNCTIONS: aclrscr()\n");
pl("aupdatexy() - updates axpos and aypos after a printf\n");
aupdatexy();
pl("aupdatexy1() - same as aupdatexy except that it uses low memory to get values\n");
aupdatexy1();
ahome(); /* MAJOR BUG HERE */
pl("ahome()");
aclreol();
pl("");
pl(" aclreol() - Note how everything disappeared to the right?");
adown(5);
pl("adown(5)");
aleft(25);
pl("aleft(25)");
aup(2);
pl("aup(2)");
aright(7);
pl("aright(7)");
agotoxy(1,12);
pl("agotoxy(1,12)");
pl("\nasavecursor() - Note the cursor location now ->");
asavecursor();
// Note this next line uses oldgotoxy which does not update the global variables axpos and aypos
oldgotoxy(1,24);
pl("gotoxy(1,24) - This goto uses some other goto function that doesn't update axpos and aypos so aforcegotoxy can help to resolve");
aforcegotoxy(1,12);
pl("aforcegotoxy(1,12)");
arestorecursor();
pl("X\narestorecursor() - location is restored to where the X above is placed");
/* COLOR FUNCTIONS */
aclrscr();
pl("COLOR FUNCTIONS:\n");
acolor(ATTR(YELLOW, GREEN));
pl("acolor(ATTR(YELLOW,GREEN))\n");
atextattr(ATTR(WHITE,BLUE));
pl("atextattr(ATTR(WHITE,BLUE)) - same as acolor\n");
atextcolor(LIGHTRED);
pl("atextcolor(LIGHTRED) - foreground color\n");
atextbackground(RED);
pl("atextbackground(RED) - background color\n");
aresetcolor();
pl("aresetcolor()\n");
ahighlight();
pl("ahighlight() or ahighvideo()\n");
ablink();
pl("ablink()\n");
anohighlight();
pl("anohighlight() or alowvideo()\n");
// anormvideo()
anoblink();
pl("anoblink()\n\nThese next 3 functions are special ANSI color commands and behave differently\n on different emulators. See DOCS.\n");
aunderline(;);
pl("aunderline(equation) ");
areverse(;);
pl("areverse(equation) ");
ainvisible(;);
pl("ainvisible(equation)\n");
oldcolor(7);
printf("That last color was ainvisible() in case you could not see it.\n\n");
pl("The color has been changed using a function that doesn't update acurattr,\n so aforcecolor can be used to resolve\n");
aforcecolor(ATTR(WHITE,CYAN));
pl("aforcecolor(ATTR(WHITE,CYAN))\n");
/* MISCELLANEOUS FUNCTIONS */
acolor(7);
aclrscr();
pl("MISCELLANEOUS FUNCTIONS:\n");
printf(
"Multiple test methods that test for ANSI presence -\n"
"atest()\n"
" aresult(): "
);
atest();
for (i=0;kbhit();i++) // read input buffer
s[i]=getch();
if (aresult(s))
printf("TRUE\n");
else
printf("FALSE\n");
printf(
"atest1()\n"
" aresult1(): "
);
atest1();
if (aresult1())
printf("TRUE\n");
else
printf("FALSE\n");
printf("aresult2(): ");
if (aresult2())
printf("TRUE\n");
else
printf("FALSE\n");
atest();
for (i=0;kbhit();i++) // read input buffer
s[i]=getch();
i=awherexy(s);
printf("awherexy(): Cursor at X:%d Y:%d at beginning of this line\n\n", i/256, i%256);
pl("akeyboard() will allow you to redefine keyboard or create macros if your ANSI\n emulator supports them.\n");
pl("asetmode() and aresetmode() changes screen modes and variable options. Watch.\n\nasetmode(CO40)");
asetmode(C40);
pl("now back to asetmode(C80)");
asetmode(C80);
pl("\n\n\n\nanocursorwrap() - turns off cursor wrap\n");
anocursorwrap();
// These printf strings exceed 80 columns.
printf("01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\n");
pl("acursorwrap() - turns it back on.. Below is the same string as it should have\n appeared.\n");
acursorwrap();
printf("01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\n");
pl("That concludes DEMOANSI tests.. ");
return;
}
results(int testnum) {
aforcegotoxy(57, 1);
aforcecolor(7);
pl("Press a key for results");
aclrscr();
printf("TEST %d\n", testnum);
printf("\nOPTIMIZED ANSI STATISTICS (OPTANSI)\n");
printf(
"Total number of characters counted in 100 repetitions of ANSI output: %5d\n"
"At 2400 baud that would equate to %2.2f seconds.\n"
"At 9600 baud that would equate to %2.2f seconds.\n"
"Time of operations on this computer was %2.4f seconds.\n",
ocnt, ocnt/240.0, ocnt/960.0, (float) otime/CLK_TCK);
printf("\nNON-OPTIMIZED ANSI STATISTICS (OTHER LIBRARIES)\n");
printf(
"Total number of characters counted in 100 repetitions of ANSI output: %5d\n"
"At 2400 baud that would equate to %2.2f seconds.\n"
"At 9600 baud that would equate to %2.2f seconds.\n"
"Time of operations on this computer was %2.4f seconds.\n",
nocnt, nocnt/240.0, nocnt/960.0, (float) notime/CLK_TCK);
printf("\nRELATIONAL IMPROVEMENT WHEN USING OPTANSI\n");
printf(
"Percent of output reduced using OptAN